/**
 * creation: 7-mrt-2008
 */
package org.jfonia.connect;

/**
 * Simple implementation of Value<T> which holds an object of type T
 * and has the ability to inform zero or more Callables when a change of value
 * occurs. 
 * 
 * 
 * @author wijnand.schepens@gmail.com
 *
 */
public class SimpleValue<T> extends ValueNode implements MutableValue<T>
{
	protected T value;
	protected String name = "";
	
	/**
	 * Creates a simpleValue with given initial value.
	 * @param value initial value
	 */
	public SimpleValue(T value)		// TODO: this ctor necessary?
	{
		this.value = value;
		// TODO: call(this) necessary?
	}

	public SimpleValue(String name, T value)		// TODO: this ctor necessary?
	{
		this.name = name;
		this.value = value;
		// TODO: call(this) necessary?
	}

	// TODO: default constructor necessary?
	
	/**
	 * Substitutes current value by 'newValue' and calls 'this'.
	 * (causing listeners to be informed)  
	 * @param newValue the new value
	 */
	public void set(T newValue) 
	{
		this.value = newValue;
		call(this);
		setValid(true);	// always true
	}
	
	/**
	 * Gets the current value.
	 * @return current value 
	 */
	public T get()
	{
		return value;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
